package com.ruoyi.web.controller.shape;

import java.util.List;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.shape.domain.Shape;
import com.ruoyi.shape.domain.ShapeUser;
import com.ruoyi.shape.service.IShapeUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户选择的手型脸型信息Controller
 *
 * @author ruoyi
 * @date 2024-03-08
 */
@RestController
@RequestMapping("/shapeUser")
public class ShapeUserController extends BaseController
{
    @Autowired
    private IShapeUserService shapeUserService;

    /**
     * 查询用户选择的手型脸型信息
     */
    @PreAuthorize("@ss.hasPermi('shapeUser:list')")
    @GetMapping("/getByUserId/{userId}")
    public AjaxResult list(@PathVariable Long userId)
    {
        ShapeUser shapeUser=shapeUserService.selectShapeUserById(userId);
        if(shapeUser!=null) {
            return AjaxResult.success(shapeUserService.selectShapeUserById(userId));
        }else
            throw new CustomException("信息不存在");
    }

    /**
     * 导出用户选择的手型脸型信息列表
     */
    @PreAuthorize("@ss.hasPermi('shapeUser:export')")
    @Log(title = "用户选择的手型脸型信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ShapeUser shapeUser)
    {
        startPage();
        List<ShapeUser> list = shapeUserService.selectShapeUserList(shapeUser);
        ExcelUtil<ShapeUser> util = new ExcelUtil<ShapeUser>(ShapeUser.class);
        return util.exportExcel(list, "用户选择的手型脸型信息数据");
    }

//    /**
//     * 获取用户选择的手型脸型信息详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('shapeUser:query')")
//    @GetMapping( "/getOne/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return AjaxResult.success(shapeUserService.selectShapeUserById(id));
//    }



    /**
     * 新增用户选择的手型脸型信息
     */
    @PreAuthorize("@ss.hasPermi('shapeUser:add')")
    @Log(title = "用户选择的手型脸型信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody ShapeUser shapeUser)
    {
        ShapeUser shapeUser1=new ShapeUser();
        shapeUser1.setUserId(shapeUser.getUserId());
        List<ShapeUser> list=shapeUserService.selectShapeUserList(shapeUser1);
        if(list.size()>0) {
            throw new CustomException("重复添加");
        }
        else
        return toAjax(shapeUserService.insertShapeUser(shapeUser));
    }

    /**
     * 修改用户选择的手型脸型信息
     */
    @PreAuthorize("@ss.hasPermi('shapeUser:edit')")
    @Log(title = "用户选择的手型脸型信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ShapeUser shapeUser)
    {
        shapeUser.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(shapeUserService.updateShapeUser(shapeUser));
    }

    /**
     * 删除用户选择的手型脸型信息
     */
    @PreAuthorize("@ss.hasPermi('shapeUser:remove')")
    @Log(title = "用户选择的手型脸型信息", businessType = BusinessType.DELETE)
	@PostMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shapeUserService.logicDeleteShapeUser(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
